package crs.direcciones.contacto.dao;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import crs.direcciones.contacto.model.CrsContacto;



/**
 * Home object for domain model class CrsContacto.
 * @see .CrsContacto
 * @author Hibernate Tools
 */
@Repository
public class CrsContactoDaoImpl implements CrsContactoDao{

	private static final Log log = LogFactory.getLog(CrsContactoDaoImpl.class);

	@Autowired
	private SessionFactory sf;
	
	public void persist(CrsContacto transientInstance) {
		log.debug("persisting CrsContacto instance");
		try {
			sf.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void remove(CrsContacto persistentInstance) {
		log.debug("removing CrsContacto instance");
		try {
			sf.getCurrentSession().delete(persistentInstance);
			log.debug("remove successful");
		} catch (RuntimeException re) {
			log.error("remove failed", re);
			throw re;
		}
	}

	public CrsContacto merge(CrsContacto detachedInstance) {
		log.debug("merging CrsContacto instance");
		try {
			CrsContacto result = (CrsContacto) sf.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public CrsContacto findById(int id) {
		log.debug("getting CrsContacto instance with id: " + id);
		try {
			CrsContacto instance = (CrsContacto) sf.getCurrentSession().get(CrsContacto.class, id);			log.debug("get successful");
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
}
